package com.zzl.car.service;

import com.zzl.car.entity.CarBaseInfo;
import com.zzl.car.mapper.CarBaseInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarBaseInfoService {

    @Autowired
    private CarBaseInfoMapper carBaseInfoMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    /*
    * 根据id获取到车辆的基础信息记录
    * */
    public CarBaseInfo getCarBaseInfoById(Integer id){
        return carBaseInfoMapper.getCarBaseInfoById(id);
    }

    /*
    * 获取到车辆的品牌
    * */
    public List<String> getAllBrand(){
        List<String> carBranch = null;
        carBranch = redisTemplate.opsForList().range("carBranch", 0, -1);
        if(carBranch.size()==0){
            carBranch = carBaseInfoMapper.getBrand();
            // 存入缓存
            redisTemplate.opsForList().rightPushAll("carBranch",carBranch);
        }
       return carBranch;
    }
}
